<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>CentOS8搭建web服务器 - 轻风筝</title><meta name="Description" content=""><meta property="og:title" content="CentOS8搭建web服务器" />
<meta property="og:description" content="前置环境 CentOS8更换阿里云源 #备份源 2021年12月31日停止使用 [root@localhost ~]# mv /etc/yum.repos.d/CentOS-Linux-Base.repo /etc/yum.repos.d/CentOS-Linux-Base.repo.backup #更换源 2021年12月31日停止使用 [root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo #或者 2" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://codebai.gitee.io/posts/centos8%E6%90%AD%E5%BB%BAweb%E6%9C%8D%E5%8A%A1%E5%99%A8/" /><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-05-05T22:08:07+08:00" />
<meta property="article:modified_time" content="2022-05-05T22:08:07+08:00" />

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="CentOS8搭建web服务器"/>
<meta name="twitter:description" content="前置环境 CentOS8更换阿里云源 #备份源 2021年12月31日停止使用 [root@localhost ~]# mv /etc/yum.repos.d/CentOS-Linux-Base.repo /etc/yum.repos.d/CentOS-Linux-Base.repo.backup #更换源 2021年12月31日停止使用 [root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo #或者 2"/>
<meta name="application-name" content="轻风筝">
<meta name="apple-mobile-web-app-title" content="轻风筝"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://codebai.gitee.io/posts/centos8%E6%90%AD%E5%BB%BAweb%E6%9C%8D%E5%8A%A1%E5%99%A8/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "CentOS8搭建web服务器",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/codebai.gitee.io\/posts\/centos8%E6%90%AD%E5%BB%BAweb%E6%9C%8D%E5%8A%A1%E5%99%A8\/"
        },"genre": "posts","wordcount":  2057 ,
        "url": "https:\/\/codebai.gitee.io\/posts\/centos8%E6%90%AD%E5%BB%BAweb%E6%9C%8D%E5%8A%A1%E5%99%A8\/","datePublished": "2022-05-05T22:08:07+08:00","dateModified": "2022-05-05T22:08:07+08:00","publisher": {
            "@type": "Organization",
            "name": "admin"},"author": {
                "@type": "Person",
                "name": "admin"
            },"description": ""
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : '' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="轻风筝"><img
        class="lazyload logo"
        src="/svg/loading.min.svg"
        data-src="/lib/img/head.jpg"
        data-srcset="/lib/img/head.jpg, /lib/img/head.jpg 1.5x, /lib/img/head.jpg 2x"
        data-sizes="auto"
        alt="/lib/img/head.jpg"
        title="/lib/img/head.jpg" />轻风筝</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="轻风筝"><img
        class="lazyload logo"
        src="/svg/loading.min.svg"
        data-src="/lib/img/head.jpg"
        data-srcset="/lib/img/head.jpg, /lib/img/head.jpg 1.5x, /lib/img/head.jpg 2x"
        data-sizes="auto"
        alt="/lib/img/head.jpg"
        title="/lib/img/head.jpg" />轻风筝</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">CentOS8搭建web服务器</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="https://codebai.gitee.io/" title="Author" target="_blank" rel="noopener noreffer author" class="author"><i class="fas fa-user-circle fa-fw"></i>admin</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-05-05">2022-05-05</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 2057 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 5 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents"></nav></div>
            </div><div class="content" id="content"><h1 id="前置环境">前置环境</h1>
<p>CentOS8更换阿里云源</p>
<pre tabindex="0"><code>#备份源 2021年12月31日停止使用
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Linux-Base.repo /etc/yum.repos.d/CentOS-Linux-Base.repo.backup
#更换源 2021年12月31日停止使用
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
#或者 2021年12月31日停止使用
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
</code></pre><p><strong>注意：从2021年12月31日起，CentOS 8操作系统版本结束了生命周期（EOL），Linux社区已不再维护该操作系统版本。</strong>
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/04c87d1384404c5d96d5b4d892d3343d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6L276aOO562d,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/04c87d1384404c5d96d5b4d892d3343d.png?x-oss-process=image/watermark%2ctype_d3F5LXplbmhlaQ%2cshadow_50%2ctext_Q1NETiBA6L276aOO562d%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/04c87d1384404c5d96d5b4d892d3343d.png?x-oss-process=image/watermark%2ctype_d3F5LXplbmhlaQ%2cshadow_50%2ctext_Q1NETiBA6L276aOO562d%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/04c87d1384404c5d96d5b4d892d3343d.png?x-oss-process=image/watermark%2ctype_d3F5LXplbmhlaQ%2cshadow_50%2ctext_Q1NETiBA6L276aOO562d%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/04c87d1384404c5d96d5b4d892d3343d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6L276aOO562d,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="CentOS 8 EOL" />
阿里云centos源地址：<a href="https://developer.aliyun.com/mirror/centos" target="_blank" rel="noopener noreffer">https://developer.aliyun.com/mirror/centos</a>
<strong>下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/</strong>
centos8（centos8官方源已下线，建议切换centos-vault源）</p>
<pre tabindex="0"><code>[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
或者
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
</code></pre><p><strong>运行 yum makecache 生成缓存</strong></p>
<pre tabindex="0"><code>[root@localhost ~]# yum makecache
</code></pre><p>或者直接</p>
<pre tabindex="0"><code>[root@localhost ~]# yum clean all &amp;&amp; yum makecache
</code></pre><p>安装net-tools，不然使用不了ifconfig命令，看不了ip地址</p>
<pre tabindex="0"><code>[root@localhost ~]# yum install net-tools -y
</code></pre><p>安装vim编辑器</p>
<pre tabindex="0"><code>[root@localhost ~]# yum install vim -y
</code></pre><h1 id="安装apache用于网站访问">安装apache，用于网站访问</h1>
<pre tabindex="0"><code>[root@localhost ~]# yum install httpd -y
</code></pre><p>启动httpd</p>
<pre tabindex="0"><code>[root@localhost ~]# service httpd start
</code></pre><p>ifconfig查看ip地址</p>
<pre tabindex="0"><code>[root@localhost ~]# ifconfig
ens33: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500
        inet 192.168.1.110  netmask 255.255.255.0  broadcast 192.168.1.255
        ether 00:0c:29:0f:c9:8a  txqueuelen 1000  (Ethernet)
        RX packets 2046993  bytes 955001567 (910.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2187370  bytes 281197289 (268.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73&lt;UP,LOOPBACK,RUNNING&gt;  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10&lt;host&gt;
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2451  bytes 106588 (104.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2451  bytes 106588 (104.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
</code></pre><p>现在还访问不了，因为需要关闭防火墙</p>
<pre tabindex="0"><code>[root@localhost ~]# service firewalld stop
</code></pre><p>检测是否安装php，如果什么信息也没有，那么你就要自己安装php了</p>
<pre tabindex="0"><code>[root@localhost ~]# rpm -qa | grep php
</code></pre><h1 id="安装php">安装php</h1>
<pre tabindex="0"><code>[root@localhost ~]# yum install -y php
</code></pre><p>安装php-mysql扩展</p>
<pre tabindex="0"><code>[root@localhost ~]# yum install php-mysqlnd -y
</code></pre><p>再次检测，看是否安装。看到如下信息就证明安装成功了。</p>
<pre tabindex="0"><code>[root@localhost ~]# rpm -qa | grep php
php-cli-5.3.3-26.el6.i686
php-5.3.3-26.el6.i686
php-common-5.3.3-26.el6.i686
省略...
[root@localhost ~]# 
</code></pre><p>重新启动Apache服务</p>
<pre tabindex="0"><code>[root@localhost ~]# service httpd restart
</code></pre><p>测试php。在/var/www/html/目录下创建一个index.php文件。然后在浏览器输入http://127.0.0.1/index.php</p>
<pre tabindex="0"><code>[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# touch index.php
[root@localhost html]# gedit index.php
&lt;?php
    echo &#34;hello php&#34;;
?&gt;
</code></pre><p>安装gd库，支持php图形验证码。在终端输入命令“yum install -y php-gd”</p>
<pre tabindex="0"><code>[root@localhost ~]# yum install -y php-gd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
=============================================================================================================================
 Package                      Arch                       Version                            Repository                  Size
=============================================================================================================================
Installing:
 php-gd                       i686                       5.3.3-26.el6                       base                       105 k
Installing for dependencies:
 libXpm                       i686                       3.5.10-2.el6                       base                        50 k                                                                                        
Dependency Installed:
  libXpm.i686 0:3.5.10-2.el6                                                                                                
Complete!
[root@localhost ~]# rpm -qa | grep php-gd
php-gd-5.3.3-26.el6.i686
[root@localhost ~]# 
</code></pre><h1 id="安装mysql">安装mysql</h1>
<pre tabindex="0"><code>[root@localhost ~]# yum install mysql mysql-server -y
</code></pre><p>启动mysql服务</p>
<pre tabindex="0"><code>[root@localhost ~]# service mysqld start
</code></pre><p>进入mysql</p>
<pre tabindex="0"><code>[root@localhost ~]# mysql -u root
</code></pre><p>创建用户</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="n">USE</span><span class="w"> </span><span class="n">mysql</span><span class="p">;</span><span class="w"> </span><span class="o">#</span><span class="err">创建用户需要操作</span><span class="w"> </span><span class="n">mysql</span><span class="w"> </span><span class="err">表</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="err">语法格式为</span><span class="w"> </span><span class="p">[</span><span class="o">@</span><span class="s1">&#39;host&#39;</span><span class="p">]</span><span class="w">  </span><span class="k">host</span><span class="w"> </span><span class="err">为</span><span class="w"> </span><span class="s1">&#39;localhost&#39;</span><span class="w"> </span><span class="err">表示本地登录用户，</span><span class="k">host</span><span class="w"> </span><span class="err">为</span><span class="w"> </span><span class="n">IP地址或</span><span class="w"> </span><span class="n">IP</span><span class="w"> </span><span class="err">地址区间，表示指定</span><span class="n">IP地址的主机可登录</span><span class="err">，</span><span class="k">host</span><span class="w"> </span><span class="err">为</span><span class="w"> </span><span class="s2">&#34;%&#34;</span><span class="err">，表示所有主机都可登录，省略代表所有主机</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">CREATE</span><span class="w"> </span><span class="k">USER</span><span class="w"> </span><span class="s1">&#39;username&#39;</span><span class="p">[</span><span class="o">@</span><span class="s1">&#39;host&#39;</span><span class="p">]</span><span class="w"> </span><span class="n">IDENTIFIED</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="s1">&#39;password&#39;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="n">eg</span><span class="p">.</span><span class="w"> </span><span class="err">常见</span><span class="w"> </span><span class="n">local_user</span><span class="w"> </span><span class="err">用户可以在所有主机登录，密码为</span><span class="w"> </span><span class="mi">123456</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">CREATE</span><span class="w"> </span><span class="k">USER</span><span class="w"> </span><span class="s1">&#39;local_user&#39;</span><span class="w"> </span><span class="n">IDENTIFIED</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="s1">&#39;123456&#39;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="n">eg</span><span class="p">.</span><span class="w"> </span><span class="err">创建</span><span class="w"> </span><span class="n">local_user</span><span class="w"> </span><span class="err">只允许在本地登录</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">CREATE</span><span class="w"> </span><span class="k">USER</span><span class="w"> </span><span class="s1">&#39;local_user&#39;</span><span class="o">@</span><span class="s1">&#39;localhost&#39;</span><span class="w"> </span><span class="n">IDENTIFIED</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="s1">&#39;123456&#39;</span><span class="p">;</span><span class="w">
</span></span></span></code></pre></div><p>查看用户权限</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="o">#</span><span class="w"> </span><span class="err">可以通过查询</span><span class="w"> </span><span class="k">user</span><span class="w"> </span><span class="err">表获取</span><span class="w"> </span><span class="err">语法格式为</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">SELECT</span><span class="w">  </span><span class="k">privileges</span><span class="o">|*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="k">user</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="o">`</span><span class="k">user</span><span class="o">`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;username&#39;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="n">eg</span><span class="p">.</span><span class="w"> </span><span class="err">查看</span><span class="w"> </span><span class="n">local_user</span><span class="w"> </span><span class="err">的权限</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="k">user</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="o">`</span><span class="k">user</span><span class="o">`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;local_user&#39;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="err">也可以用</span><span class="w"> </span><span class="k">SHOW</span><span class="w"> </span><span class="n">GRANTS</span><span class="w"> </span><span class="err">查看</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">SHOW</span><span class="w"> </span><span class="n">GRANTS</span><span class="w"> </span><span class="k">FOR</span><span class="w"> </span><span class="s1">&#39;username&#39;</span><span class="w"> </span><span class="p">[</span><span class="o">@</span><span class="k">host</span><span class="p">];</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="n">eg</span><span class="p">.</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">SHOW</span><span class="w"> </span><span class="n">GRANTS</span><span class="w"> </span><span class="k">FOR</span><span class="w"> </span><span class="n">local_user</span><span class="p">;</span><span class="w">
</span></span></span></code></pre></div><p>赋予权限</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="o">#</span><span class="w"> </span><span class="err">语法格式</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">GRANT</span><span class="w"> </span><span class="k">privileges</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="k">database</span><span class="p">.</span><span class="k">table</span><span class="w"> </span><span class="k">TO</span><span class="w"> </span><span class="s1">&#39;username&#39;</span><span class="o">@</span><span class="s1">&#39;host&#39;</span><span class="w"> </span><span class="p">[</span><span class="n">IDENTIFIED</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="s1">&#39;password&#39;</span><span class="p">];</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="n">eg</span><span class="p">.</span><span class="w"> </span><span class="err">赋予</span><span class="w"> </span><span class="n">local_user</span><span class="w"> </span><span class="err">在所有主机的所有权限，但不包含给其他账号赋予权限的权限</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">GRANT</span><span class="w"> </span><span class="k">all</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="o">*</span><span class="p">.</span><span class="o">*</span><span class="w"> </span><span class="k">TO</span><span class="w"> </span><span class="s1">&#39;local_user&#39;</span><span class="o">@</span><span class="s1">&#39;%&#39;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="err">用户授权数据库</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">grant</span><span class="w"> </span><span class="k">select</span><span class="p">,</span><span class="k">insert</span><span class="p">,</span><span class="k">update</span><span class="p">,</span><span class="k">delete</span><span class="p">,</span><span class="k">create</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="p">[</span><span class="err">数据库名称</span><span class="p">].</span><span class="o">*</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="p">[</span><span class="err">用户名称</span><span class="p">];</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="o">*</span><span class="err">代表整个数据库</span><span class="p">.</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="err">例子：</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="n">mysql</span><span class="o">&gt;</span><span class="w"> </span><span class="k">grant</span><span class="w"> </span><span class="k">select</span><span class="p">,</span><span class="k">insert</span><span class="p">,</span><span class="k">update</span><span class="p">,</span><span class="k">delete</span><span class="p">,</span><span class="k">create</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="n">estuntest</span><span class="p">.</span><span class="o">*</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="n">estuntest</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="n">Query</span><span class="w"> </span><span class="n">OK</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="k">rows</span><span class="w"> </span><span class="n">affected</span><span class="w"> </span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">00</span><span class="w"> </span><span class="n">sec</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="err">授权某个用户拥有某个数据库的所有权限</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">GRANT</span><span class="w"> </span><span class="k">ALL</span><span class="w"> </span><span class="k">privileges</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">test_db</span><span class="p">.</span><span class="o">*</span><span class="w"> </span><span class="k">TO</span><span class="w"> </span><span class="n">user_name</span><span class="o">@</span><span class="s1">&#39;%&#39;</span><span class="n">IDENTIFIED</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="s1">&#39;password&#39;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">#</span><span class="w"> </span><span class="err">刷新权限</span><span class="w"> </span><span class="err">权限更新后刷新才会起作用</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="n">FLUSH</span><span class="w"> </span><span class="k">PRIVILEGES</span><span class="p">;</span><span class="w">
</span></span></span></code></pre></div></div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2022-05-05</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"></div>
            <div class="post-info-share">
                <span></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.98.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2022</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="https://codebai.gitee.io/" target="_blank">admin</a></span><span class="icp-splitter">&nbsp;|&nbsp;</span><br class="icp-br"/>
                    <span class="icp"><a href="https://beian.miit.gov.cn" target="_blank">豫ICP备2021033195号-2</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
